<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui"%>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys"%>
<%
    String path = request.getContextPath();
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>${tabTitle}</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
	<div class="Wrapper">
		<div>
			<div id="pageInTab" class="pageInTab">
				<form id="ins_cfg_info_edit_form">
					<div class="fieldset1 tabel_col clearFix">
						<div class="fieldBox col_50">
							<div class="label">机构名称</div>
							<div class="field">
								<span name="fundRasInsNm" id="fundRasInsNm">${fundRasInsNm}</span>
							</div>
						</div>
						<div class="fieldBox col_50">
							<div class="label">账户名称</div>
							<div class="field">
								<span >${cstNm}</span>
							</div>
						</div>
						<div class="fieldBox col_50">
							<div class="label">月收入</div>
							<div class="field">
								<input name="monIncmYuan" id="monIncmYuan" type="text" class="ui-textbox" value="${monIncmYuan}" validate="{number:true, maxlength:11, minlength:4}">
								<span class="requiredSymbol">*</span>
							</div>
						</div>
						<div class="fieldBox col_50">
							<div class="label">开户银行</div>
							<div class="field">
                                <select name="bkCd" id="bkCd" value="${bkCd}" validate="{required:true}">
	                                <c:if test="${bkCd == null || bkCd == ''}">
	                                	<option value="" selected="selected">--请选择--</option>
	                                </c:if>
	                                <c:if test="${bkCd != null && bkCd != ''}">
	                                	<option value="">--请选择--</option>
	                                </c:if>
                                    <c:forEach items="${bankList}" var="item">
                                    	<c:if test="${item.key == bkCd}">
                                        	<option value="${item.key}" selected="selected">${item.value}</option>
                                    	</c:if>
                                    	<c:if test="${item.key != bkCd}">
                                        	<option value="${item.key}">${item.value}</option>
                                    	</c:if>
                                    </c:forEach>
                                </select>
								<span class="requiredSymbol">*</span>
							</div>
						</div>
						<div class="fieldBox col_50">
							<div class="label">银行账号</div>
							<div class="field">
								<input name="accNo" id="accNo" type="text" class="ui-textbox" value="${accNo}" validate="{number:true, maxlength:22, minlength:15}">
								<span class="requiredSymbol">*</span>
							</div>
						</div> 
						<div class="fieldBox col_50">
							<div class="label">开户行号</div>
							<div class="field">
								<input name="bkNo" id="bkNo" type="text" class="ui-textbox" value="${bkNo}" validate="{number:true, maxlength:30}">
								<span class="requiredSymbol">*</span>
							</div>
						</div>
						<div class="fieldBox col_50">
							<div class="label">预留手机号</div>
							<div class="field">
								<input name="mp" id="mp" type="text" class="ui-textbox" value="${mp}" validate="{number:true, maxlength:11, minlength:11}">
								<span class="requiredSymbol">*</span>
							</div>
						</div>
                        <div class="fieldBox col_50">
		                    <div class="label">证件有效起始日期</div>
		                    <div class="field">
		                        <input name="certValidSDt" id="certValidSDt" type="text" class="ui-datepicker" value="${certValidSDt}" validate="{required:true}">
								<span class="requiredSymbol">*</span>
		                    </div>
		                </div>
		                <div class="fieldBox col_50 col_fix_photo">
		                    <div class="label">证件有效终止日期</div>
		                    <div class="field">
								<input name="certValidEDt" id="certValidEDt" type="text" class="ui-datepicker" value="${certValidEDt}" >
								<div><input type="checkbox" name="checkOne" id="checkOne"  <c:if test="${certValidEDt=='长期'}">checked</c:if> value="长期" onchange="enduring(this)">长期</div>
								<span class="requiredSymbol">*</span>
		                    </div>
		                </div>
                         <%-- <div class="fieldBox col_100_auto" style="width:66.6%">
                           <div class="label">区域</div>
                            <div class="field">
                                <jsp:include page="../../system/sysRegion/sysStdRegionOne.jsp" flush="true">
                                    <jsp:param name="regionShowLvl"  value="3"/>
                                </jsp:include>
                            </div>
                            <span class="requiredSymbol">*</span>
                        </div> --%>
                         <div class="fieldBox col_100_auto" style="width:66.6%">
                            <div class="label">上牌城市</div>
                            <div class="field">
                                <jsp:include page="../../system/sysRegion/sysStdRegionOne.jsp" flush="true">
                                    <jsp:param name="regionShowLvl"  value="3"/>
                                </jsp:include>
                            </div>
                        </div>
						<!-- hide data -->
						<div class="fieldBox col_100" style="display: none;">
							<div class="field">
								<input name="prjId" id="prjId" type="text" class="ui-textbox" value="${prjId}">
								<input name="cstId" id="cstId" type="text" class="ui-textbox" value="${cstId}">
								<input name="cstNm" id="cstNm" type="text" class="ui-textbox" value="${cstNm}">
								<input name="cstAccInfoId" id="cstAccInfoId" type="text" class="ui-textbox" value="${cstAccInfoId}">
								<input name="fundRasInsId" id=fundRasInsId type="text" class="ui-textbox" value="${fundRasInsId}">
							</div>
						</div>
					</div>
	                <div id="saveInsCfgDiv" class="btnsBox">
	                    <sys:FlowFrmAth preTaskIds="${preTaskIds}" athCd="addPrjBscInfo" pInstId="${pInstId}">
	                        <span id="saveInsCfg" class="sq-button sq-button-round" onclick="return saveInfo();">保存</span>
	                    </sys:FlowFrmAth>
                	</div>
				</form>
			</div>
		</div>
	</div>

<script type="text/javascript">

var detailFlag = '${detailFlag}';
var rgnProCd = '${rgnProCd}';
var rgnCtCd = '${rgnCtCd}';
var rgnTwCd = '${rgnTwCd}';
var updateFlag = '${updateFlag}';
var mainData;
//定义修改时回显值,需要调用页面在回显值的时候改变这几个值
var _sysStdProvCdUpdateValue = "";//省
var _sysStdCityCdUpdateValue = "";//市
var _sysStdDistCdUpdateValue = "";//县
// REQ-7008 信审初审节点 客户经理 可修改字段
var fromCAFlag = '${fromCAFlag}';
var fromCMFlag = '${fromCMFlag}';
var certValidEDt;
$(function () {
	initData();
	setData();
	enduring();
});

function initData() {
    $("#ins_cfg_info_edit_form").ligerForm({
        validate: true
    });
	
	disabledInput();
    disabledInput2();
	enableFields();
}
//回显区域
function setData() {
	setSysStdProvCdUpdateValue(rgnProCd);//省
	setSysStdCityCdUpdateValue(rgnCtCd);//市
	setSysStdDistCdUpdateValue(rgnTwCd);//县
}

 function disabledInput() {
	if(detailFlag == "true") {
		liger.get("bkCd").setDisabled();
		liger.get("bkNo").setDisabled();
		liger.get("accNo").setDisabled();
		liger.get("mp").setDisabled();
		liger.get("certValidSDt").setDisabled();
		liger.get("certValidEDt").setDisabled();
		 liger.get("regStdProvCd").setDisabled();
		liger.get("regStdCityCd").setDisabled();
		liger.get("regStdDistCd").setDisabled(); 
		liger.get("monIncmYuan").setDisabled();
		liger.get("cstNm").setDisabled();
		$("#saveInsCfgDiv").hide();
	}
}


function disabledInput2() {
    if(updateFlag == "true") {
        liger.get("bkCd").setDisabled();
        liger.get("accNo").setDisabled();
        liger.get("mp").setDisabled();
        liger.get("regStdProvCd").setDisabled();
        liger.get("regStdCityCd").setDisabled();
        liger.get("regStdDistCd").setDisabled();
        liger.get("monIncmYuan").setDisabled();
        liger.get("cstNm").setDisabled();
    }
}

function enableFields() {
	if (null != fromCAFlag && "true" == fromCAFlag) {
		liger.get("monIncmYuan").setEnabled();
		liger.get("certValidSDt").setEnabled();
		liger.get("certValidEDt").setEnabled();
		liger.get("regStdProvCd").setEnabled();
		liger.get("regStdCityCd").setEnabled();
		liger.get("regStdDistCd").setEnabled();
		$("#saveInsCfgDiv").show();
	}
	if (null != fromCMFlag && "true" == fromCMFlag) {
		liger.get("monIncmYuan").setEnabled();
		liger.get("certValidSDt").setEnabled();
		liger.get("certValidEDt").setEnabled();
		liger.get("regStdProvCd").setEnabled();
		liger.get("regStdCityCd").setEnabled();
		liger.get("regStdDistCd").setEnabled();
		$("#saveInsCfgDiv").show();
	}
}

/**
 * 校验时间格式
 */
function checkDateFormat(){
	var flag = 0;
	var params = {};
	params["certValidSDt"] = $("#certValidSDt").val();
	params["certValidEDt"] = $("#certValidEDt").val();
	$.ajax({
		type:'get',
		dataType:'json',
		async:false,
		url:'<%=path%>/customer/cstbscinfo/checkCertValid.do',
		data:params,
		success:function(data){
			//$.ligerDialog.SQalert({content: data.info,SQ_type: "success"});	
			if(data.success == 1){
				var oDate1 = new Date($("#certValidSDt").val());
		        var oDate2 = new Date($("#certValidEDt").val());
		        if(oDate1.getTime() < oDate2.getTime()){
					flag = 1;
		        }
		        else {
		        	UIUtils.alertError("证件有效起始日期 不能大于等于 证件有效终止日期");
		        }
			}else{
				UIUtils.alertError(data.info);
			}
		},
		error:function(data){
			UIUtils.alertError(data.info);
		}
	});
	return flag;
}
//初始化省
function rgnProvList(){
	$.ajax({
		type: 'post',
		dataType:'json',
		url : '<%=path%>/project/prjBscInfoInsDistribute/searchsearchStdProvinceList.do',
		success:function(msg){
			 if(msg.success == 1){
				 var provSelectObj = liger.get("rgnProvCd");
				 provSelectObj.setData(msg.data);
			 }else{
				 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
			 }
		}
	});
}
//初始化市级数据(value:省代码)
function rgnCityList(){
	function initRegionCitySelectData(value){
		if(!$("#rgnCityCd").length)return;
		var provSelectObj = liger.get("rgnProvCd");
		var _provCd = provSelectObj.findValueByText(value);
		if(!_provCd){
			return;
		}
		$.ajax({
			type: 'post',
			dataType:'json',
			data:{rgnCd:_provCd},
			url: '<%=path%>/project/prjBscInfoInsDistribute/searchRegionByRgnPid.do',
			success:function(msg){
				 if(msg.success == 1){
					 var citySelectObj = liger.get("rgnCityCd");
					 if(msg.data){
						 citySelectObj.setData(msg.data);
					 }else{
						 citySelectObj.clear();
						 citySelectObj.setData({});//置空下拉框数据
						 var countySelectObj = liger.get("rgnCountyCd");
						 if(countySelectObj){
							 countySelectObj.clear();
							 countySelectObj.setData({});//置空下拉框数据
						 }
					 }
				 }else{
					 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
				 }
			}
		});
	}
}
//初始化县/区数据(value:市代码)
function s (){
	
	function initCountySelectData(value){
		if(!$("#rgnCountyCd").length)return;
		var citySelectObj = liger.get("rgnCityCd");
		var _cityCd = citySelectObj.findValueByText(value);
		if(!_cityCd){
			return;
		}
		$.ajax({
			type: 'post',
			dataType:'json',
			data:{rgnCd:_cityCd},
			url: '<%=path%>/system/sysstdregion/searchRegionByRgnPid.do',
			success:function(msg){
				 if(msg.success == 1){
					 var countySelectObj = liger.get("rgnCountyCd");
					 if(msg.data){
						 countySelectObj.setData(msg.data);
						 if(StringUtils.isNotEmpty(_rgnCountyUpdataValue)){
							 countySelectObj.selectValue(_rgnCountyUpdataValue);
						 }else{
							 //countySelectObj.selectValue(msg.data[0].key);
						 }
					 }else{
						 countySelectObj.clear();
						 countySelectObj.setData({});//置空下拉框数据
					 }
				 }else{
					 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
				 }
			}
		});
	}
}
// 保存项目客户信息，后面弹出准入验证的资料确认页
function saveInfo() {
	var ligerForm = liger.get("ins_cfg_info_edit_form");
    if (!ligerForm.valid()) {
        top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
        return false; //验证不通过，不执行以下代码
    }        

	// 校验 身份证生效日 和 身份证到期日 数据格式

	if(!$("#certValidSDt").val()){
		top.$.ligerDialog.SQalert({content: "请选择证件有效起始日期！", SQ_type: "error"});
		return false;
	}
	if(null == certValidEDt && !$("#certValidEDt").val()){
		top.$.ligerDialog.SQalert({content: "请选择证件有效终止日期！", SQ_type: "error"});
		return false;
	}
	// if(checkDateFormat() != 1){
	// 	return ;
	// }
    var data = ligerForm.getData();
    if(!$("#regStdProvCd").val()){
        top.$.ligerDialog.SQalert({content: "区域-省不能为空！", SQ_type: "error"});
        return false;
    }
	if(!$("#regStdCityCd").val()){
        top.$.ligerDialog.SQalert({content: "区域-市不能为空！", SQ_type: "error"});
        return false;
    }
	if(!$("#regStdDistCd").val()){
        top.$.ligerDialog.SQalert({content: "区域-县不能为空！", SQ_type: "error"});
        return false;
    }
	if(!$("#monIncmYuan").val()){
        top.$.ligerDialog.SQalert({content: "请填写月收入！", SQ_type: "error"});
        return false;
    }
     if(!$("#bkCd").val()){
        top.$.ligerDialog.SQalert({content: "请选择开户银行！", SQ_type: "error"});
        return false;
    }
    if(!$("#bkNo").val()){
        top.$.ligerDialog.SQalert({content: "请填写开户行号！", SQ_type: "error"});
        return false;
    }
    if(!$("#accNo").val()){
        top.$.ligerDialog.SQalert({content: "请填写银行账号！", SQ_type: "error"});
        return false;
    }
    if(!$("#mp").val()){
        top.$.ligerDialog.SQalert({content: "请填写预留手机号码！", SQ_type: "error"});
        return false;
    } 
    if(!$("#cstNm").val()){
        top.$.ligerDialog.SQalert({content: "请填写账号名称！", SQ_type: "error"});
        return false;
    }
    var index=document.getElementById("bkCd").selectedIndex;//获取当前选择项的索引.
    data["bkNm"] = document.getElementById("bkCd").options[index].text;//获取当前选择项的文本.
    data["fundRasInsId"] = $("#fundRasInsId").val();//机构
    data["bkCd"] = liger.get("bkCd").selectedValue;//开户银行
    data["bkNo"] = $("#bkNo").val();//开户行号
    data["accNo"] =  $("#accNo").val();//银行账号
    data["mp"] = $("#mp").val(); //手机号
    data["prjId"] = $("#prjId").val();//项目id
    data["cstId"] = $("#cstId").val();//客户id
    data["cstNm"] = $("#cstNm").val();//账号名称
    data["certValidSDt"] = $("#certValidSDt").val();//身份证有效期
    data["certValidEDt"] = $("#certValidEDt").val();//身份证截止日期
    data["rgnProvCd"] = getRgnProvCd();//省
    data["rgnCityCd"] = getRgnCityCd();//市
    data["rgnCountyCd"] = getRgnCountyCd();//县
    data["monIncmYuan"] = $("#monIncmYuan").val();//月收入
	if (null == certValidEDt) {
		data["certValidEDt"] = $("#certValidEDt").val();//身份证截止日期
	} else {
		data["certValidEDt"] = certValidEDt;
	}
    var url = '<%=path%>/institution/zbbank/save.do';
    var wait_dialog;
    $.ajax({
        type: 'post',
        dataType: 'json',
        data: data,
        url: url,
        beforeSend: function () {
            wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
        },
        success: function (msg) {
            wait_dialog.close();
            if (msg.success == 1) {
            	setData(msg.data);//设置数据
            	mainData = msg.data;
            	disabledInput();
            	setData();
				UIUtils.alertSuccessHold1(msg.info);
            } else {
                UIUtils.alertErrorHold1(msg.info);
            }
        }
    });
}
//选择长期置灰时间控件
function enduring(checkbox) {
	if ($("#checkOne").is(':checked')){
		$("#certValidEDt").hide();
		certValidEDt = "长期";
	} else {
		$("#certValidEDt").show();
		certValidEDt = null;
	}
}

</script>

</body>
</html>